package com.zh.javaguide.multithread;

/**
 * Copyright (C) 广州中和互联网技术有限公司
 *
 * 双重校验实现单例模式
 * @author 范家微 fanjiawei@borche.cn
 * @date :2021/1/17 22:44
 */
public class Singleton {
	private volatile static Singleton uniqueInstanse;

	private Singleton() {

	}

	public synchronized static Singleton getUniqueInstanse() {
		//先判断是否实例化，没有才进入加锁代码
		if (uniqueInstanse == null) {
			// 类对象加锁
			synchronized (Singleton.class) {
				if (uniqueInstanse == null) {
					uniqueInstanse = new Singleton();
				}
			}
		}
		return uniqueInstanse;
	}
}
